package com.developer.platform.application.query;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.developer.platform.application.query.assembler.QuartzJobAssembler;
import com.developer.platform.application.query.dto.QuartzJobDto;
import com.developer.platform.application.query.dto.ResponseModel;
import com.developer.platform.domain.QuartzJob;
import com.developer.platform.infrastructure.data.mapper.QuartzJobMapper;
import com.veeker.core.bean.Pageable;
import org.springframework.stereotype.Component;

/**
 * @author ：qiaoliang
 * @date ：2021-01-07
 */
@Component
public class QuartzJobQueryManager {

  private final QuartzJobMapper quartzJobMapper;
  private final QuartzJobAssembler quartzJobAssembler;

  public QuartzJobQueryManager(
      QuartzJobMapper quartzJobMapper,
      QuartzJobAssembler quartzJobAssembler) {
    this.quartzJobMapper = quartzJobMapper;
    this.quartzJobAssembler = quartzJobAssembler;
  }

  public ResponseModel<QuartzJobDto> list(Pageable pageable){
    LambdaQueryWrapper<QuartzJob> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.orderByDesc(QuartzJob::getCreateTime);
    return quartzJobAssembler.toQuartzJobDto(quartzJobMapper
        .selectPage(new Page<>(pageable.getPageNumber(), pageable.getPageSize()),
            queryWrapper));
  }

}
